package com.zxl.live.screen.call.helper;

import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;

import com.zxl.live.screen.R;
import com.zxl.live.screen.call.tools.CallUtils;
import com.zxl.live.screen.call.tools.TelephoneHelper;
import com.zxl.live.screen.call.ui.widget.CallFlashPanel;
import com.zxl.live.screen.call.ui.widget.InCallActionView;
import com.zxl.live.tools.common.ApplicationHelper;

/**
 * Created by Administrator on 2017/12/11.
 */
public class CallFlashHelper implements InCallActionView.OnCallActionClickListener {

    private CallFlashPanel mCallFlashPanel;

    private CallFlashWindowHelper mCallFlashWindowHelper;

    public CallFlashHelper() {
        mCallFlashWindowHelper = new CallFlashWindowHelper(ApplicationHelper.getContext());
    }

    public void onCallIn(Intent intent) {
        String comingNum = intent.getStringExtra("incoming_number");
        if (!TextUtils.isEmpty(comingNum)) {
            if (mCallFlashPanel == null) {
                mCallFlashPanel = (CallFlashPanel) LayoutInflater.from(ApplicationHelper.getContext()).inflate(R.layout.panel_call_flash, null, false);
                mCallFlashPanel.setOnCallActionClickListener(this);
            }
            mCallFlashPanel.inCall(comingNum);
            mCallFlashWindowHelper.showView(mCallFlashPanel);
        }
    }

    public void onCallEnd() {
        if (mCallFlashPanel != null) {
            mCallFlashWindowHelper.dismissView(mCallFlashPanel);
        }
    }


    @Override
    public void onAcceptClick() {
        CallUtils.acceptCall();
        ApplicationHelper.postUiThreadDelayed(new Runnable() {
            @Override
            public void run() {
                mCallFlashWindowHelper.dismissView(mCallFlashPanel);
            }
        }, 500);
    }

    @Override
    public void onRejectClick() {
        TelephoneHelper.killCall();
        ApplicationHelper.postUiThreadDelayed(new Runnable() {
            @Override
            public void run() {
                mCallFlashWindowHelper.dismissView(mCallFlashPanel);
            }
        }, 500);
    }
}
